package cn.gzsxt.music.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gzsxt.music.query.AdminQueryObject;
import cn.gzsxt.music.service.AdminService;
import cn.gzsxt.music.vo.MsgObj;

@Controller
@Scope("request")
@RequestMapping("/admin")
public class AdminController {

	@Autowired
	private AdminService service;

	@RequestMapping(value = "/addAdmin", method = RequestMethod.POST)
	@ResponseBody
	public MsgObj addAdmin(@RequestParam Map<String, Object> params) {
		params.put("create_date", new Date());
		int row = service.insert(params);

		MsgObj msgObj = new MsgObj(0, "添加用户失败");
		if (row == 1) {
			msgObj = new MsgObj(1, "添加用户成功");
		}

		return msgObj;
	}

	@RequestMapping(value = "/updateAdmin", method = RequestMethod.POST)
	@ResponseBody
	public MsgObj updateAdmin(@RequestParam Map<String, Object> params) {
		int row = service.updateAdmin(params);

		MsgObj msgObj = new MsgObj(0, "修改后台用户失败");
		if (row == 1) {
			msgObj = new MsgObj(1, "修改后台用户成功");
		}

		return msgObj;
	}

	// 后台用户列表
	@RequestMapping(value = "/adminList")
	@ResponseBody
	public Map<String, Object> adminList(AdminQueryObject qo) {

		Map<String, Object> result = service.selectAdminDataByCondition(qo);

		return result;
	}

	// 当前登录用户对应的菜单树数据
	@RequestMapping(value = "/getMenu")
	@ResponseBody
	public List<Map<String, Object>> getMenu() {
		List<Map<String, Object>> result = service.getMenu();
		return result;
	}
	
	// 当前登录用户对应的菜单树数据
	@RequestMapping(value = "/getMusicMenu")
	@ResponseBody
	public List<Map<String, Object>> getMusicMenu() {
		List<Map<String, Object>> result = service.getMusicMenu();
		return result;
	}

	// 跳转到用户列表
	@RequestMapping("adminPage")
	public String adminPage() {
		return "adminPage";
	}
}
